<template>
  <div class="ReconciliationDetail">
    <el-button size="default" @click="onExportPDF" style="margin: 40px 0 0 40px">
      <div style="display:flex;align-items: center;">
        <img style="width: 20px; height: 20px; margin-right: 10px" src="../../assets/images/pdf.png" alt="fill" />导出PDF
      </div>
    </el-button>
    <el-button size="default" @click="onExport" style="margin: 40px 0 0 40px">
      <div style="display:flex;align-items: center;">
        <img style="width: 20px; height: 20px; margin-right: 10px" src="../../assets/images/excel.png"
          alt="fill" />导出excel
      </div>
    </el-button>

    <div class="ReconciliationDetail-model" id="pdfDom">
      <div>{{ data.factory_name }} {{ data.recon_time }} 入库结账对账单</div>
      <div>
        <div>回货单</div>
        <el-table :data="data.purchaseinlist" style="width: 100%" border>
          <el-table-column label="生产加工单" align="center" prop="so_id"></el-table-column>
          <el-table-column label="合同号" align="center" prop="factory_contract_no"></el-table-column>
          <el-table-column label="采购单号" align="center" prop="po_id"></el-table-column>
          <el-table-column label="款号" align="center" prop="type_no"></el-table-column>
          <el-table-column label="款名" align="center" prop="type_name"></el-table-column>
          <el-table-column label="大货绣花成本加价总价(含税)" align="center" prop="contract_machining_price"></el-table-column>
          <el-table-column label="实付绣花成本加价总价(含税)" align="center" prop="pay_machining_price"></el-table-column>
          <el-table-column label="数量" align="center" prop="totalnum"></el-table-column>
          <el-table-column label="货款金额(含税)" align="center" prop="total_cost_amount"></el-table-column>
          <el-table-column label="开票金额" align="center" prop="emb_billing_amount"></el-table-column>
        </el-table>
        <div class="ReconciliationDetail-model-only">
          <span>回货总金额：{{ data.purchasein_amount }}</span>
          <span>回货总数量：{{ data.totalnum }}</span>
        </div>
      </div>
      <div>
        <div>工序费用</div>
        <el-table :data="data.worklist" style="width: 100%" border>
          <el-table-column label="工序加工单" align="center" prop="working_number"></el-table-column>
          <el-table-column label="合同号" align="center" prop="factory_contract_no"></el-table-column>
          <el-table-column label="款号" align="center" prop="type_no"></el-table-column>
          <el-table-column label="工厂" align="center" prop="factory_name"></el-table-column>
          <el-table-column label="单价" align="center" prop="price"></el-table-column>
          <el-table-column label="数量" align="center" prop="num"></el-table-column>
          <el-table-column label="金额" align="center" prop="amount"></el-table-column>
          <el-table-column label="交期" align="center" prop="delivery_date"></el-table-column>
          <el-table-column label="创建时间" align="center" prop="createtime"></el-table-column>
        </el-table>
      </div>
      <div>
        <div>预付款费用</div>
        <el-table :data="data.advancelist" style="width: 100%" border>
          <el-table-column label="合同号" align="center" prop="factory_contract_no"></el-table-column>
          <el-table-column label="预付款" align="center" prop="amount"></el-table-column>
          <el-table-column label="付款时间" align="center" prop="pay_time"></el-table-column>
        </el-table>
      </div>
      <div>
        <div>额外费用</div>
        <el-table :data="data.additionallist" style="width: 100%" border>
          <el-table-column label="合同号" align="center" prop="factory_contract_no"></el-table-column>
          <el-table-column label="加工单号" align="center" prop="processing_code"></el-table-column>
          <el-table-column label="款号" align="center" prop="type_no"></el-table-column>
          <el-table-column label="款名" align="center" prop="type_name"></el-table-column>
          <el-table-column label="用途" align="center" prop="purpose"></el-table-column>
          <el-table-column label="单价" align="center" prop="price"></el-table-column>
          <el-table-column label="税额" align="center" prop="tax_rate_price"></el-table-column>
          <el-table-column label="数量" align="center" prop="num"></el-table-column>
          <el-table-column label="总价" align="center" prop="amount"></el-table-column>
          <el-table-column label="备注" align="center" prop="remarks"></el-table-column>
        </el-table>
      </div>
      <div>
        <div>违约金/赔偿金</div>
        <el-table :data="data.finelist" style="width: 100%" border>
          <el-table-column label="合同号" align="center" prop="factory_contract_no"></el-table-column>
          <el-table-column label="加工单号" align="center" prop="processing_code"></el-table-column>
          <el-table-column label="款名" align="center" prop="type_name"></el-table-column>
          <el-table-column label="款号" align="center" prop="type_no"></el-table-column>
          <el-table-column label="违约金/赔偿金" align="center" prop="amount"></el-table-column>
          <el-table-column label="违约/赔偿事由" align="center" prop="reason"></el-table-column>
          <el-table-column label="备注" align="center" prop="remarks"></el-table-column>
          <el-table-column label="违约/赔偿申请日期" align="center" prop="createtime"></el-table-column>
        </el-table>
      </div>
      <div>
        <div>返修退款</div>
        <el-table :data="data.repairlist" style="width: 100%" border>
          <el-table-column label="生产加工单" align="center" prop="processing_code"></el-table-column>
          <el-table-column label="采购单" align="center" prop="po_id"></el-table-column>
          <el-table-column label="款号" align="center" prop="type_no"></el-table-column>
          <el-table-column label="大货成衣成本加价总价(含税)" align="center" prop="contract_machining_price"></el-table-column>
          <el-table-column label="实付成衣成本加价总价(含税)" align="center" prop="pay_machining_price"></el-table-column>
          <el-table-column label="数量" align="center" prop="num">
            <template slot-scope="{ row }">
              <div style="color: red">-{{ row.num }}</div>
            </template>
          </el-table-column>
          <el-table-column label="返修退款金额" align="center" prop="amount">
            <template slot-scope="{ row }">
              <div style="color: red">-{{ row.amount }}</div>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <div>
        <div>对账信息汇总</div>
        <el-table :data="data.Summary" style="width: 100%" border>
          <el-table-column label="货款金额" align="center" prop="purchasein_amount">
            <template slot-scope="{ row }">
              {{ row.purchasein_amount || 0 }}
            </template>
          </el-table-column>
          <el-table-column label="工序费用" align="center" prop="work_amount">
            <template slot-scope="{ row }">
              {{ row.work_amount || 0 }}
            </template>
          </el-table-column>
          <el-table-column label="预付款" align="center" prop="advance_amount">
            <template slot-scope="{ row }">
              {{ row.advance_amount || 0 }}
            </template>
          </el-table-column>
          <el-table-column label="额外费用" align="center" prop="additional_amount">
            <template slot-scope="{ row }">
              {{ row.additional_amount || 0 }}
            </template>
          </el-table-column>
          <el-table-column label="违约金/赔偿金金额" align="center" prop="fine_amount">
            <template slot-scope="{ row }">
              {{ row.fine_amount || 0 }}
            </template></el-table-column>
          <el-table-column label="返修退款" align="center" prop="repair_amount">
            <template slot-scope="{ row }">
              {{ row.repair_amount || 0 }}
            </template>
          </el-table-column>
          <el-table-column label="总开票金额" align="center" prop="kaip_amount">
            <template slot-scope="{ row }">
              {{ row.kaip_amount || 0 }}
            </template>
          </el-table-column>
          <el-table-column label="总应付金额" align="center" prop="pay_amount">
            <template slot-scope="{ row }">
              {{ row.pay_amount || 0 }}
            </template>
          </el-table-column>
        </el-table>
      </div>
      <div>
        <div>工厂银行信息</div>
        <el-table :data="data.bank" style="width: 100%" border>
          <el-table-column label="公司抬头" align="center" prop="company_head"></el-table-column>
          <el-table-column label="开户行" align="center" prop="bank_of_deposit"></el-table-column>
          <el-table-column label="开户行号" align="center" prop="opening_bank_no"></el-table-column>
          <el-table-column label="银行账户" align="center" prop="bank_account"></el-table-column>
        </el-table>
      </div>
    </div>
    <!-- <el-button
      type="primary"
      size="default"
      @click="onExamine"
      style="margin: 0 0 40px 40px"
      v-if="data.status == 0"
      >审核</el-button
    >-->
    <!-- 审核 -->
    <el-dialog title="审核" :visible.sync="auditdialogVisible" :lose-on-click-modal="false" width="30%">
      <div>
        <el-radio v-model="form.status" :label="1">通过</el-radio>
        <el-radio v-model="form.status" :label="0">拒绝</el-radio>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="auditdialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="onExamineAuditAffirm">确 定</el-button>
      </span>
    </el-dialog>
    <!-- <div style="width:200mm">
      <div
        style=" text-align: center;font-size: 20px;font-weight: bold;margin-bottom: 20px;"
      >测试供应商 2021-02 入库结账对账单</div>
      <div style="margin:4mm 0">
        <div style="margin:2mm 0">回货单</div>
        <table
          style="border:1px solid #EBEEF5;width: 200mm; min-height: 25px; line-height: 25px; text-align: center; border-collapse: collapse; padding:2px;"
        >
          <tr style="border:1px solid #EBEEF5;font-size:12px;color:#909399">
            <th style="border:1px solid #EBEEF5;font-size:12px;color:#909399">生产加工单</th>
            <th style="border:1px solid #EBEEF5;font-size:12px;color:#909399">采购单号</th>
            <th style="border:1px solid #EBEEF5;font-size:12px;color:#909399">款号</th>
            <th style="border:1px solid #EBEEF5;font-size:12px;color:#909399">SKU</th>
            <th style="border:1px solid #EBEEF5;font-size:12px;color:#909399">合同单价</th>
            <th style="border:1px solid #EBEEF5;font-size:12px;color:#909399">合同加工价</th>
            <th style="border:1px solid #EBEEF5;font-size:12px;color:#909399">实付单价</th>
            <th style="border:1px solid #EBEEF5;font-size:12px;color:#909399">实付加工价</th>
            <th style="border:1px solid #EBEEF5;font-size:12px;color:#909399">数量</th>
            <th style="border:1px solid #EBEEF5;font-size:12px;color:#909399">金额</th>
          </tr>
          <tr>
            <td style="border:1px solid #EBEEF5;font-size:12px;color:#909399">6666666666</td>
            <td style="border:1px solid #EBEEF5;font-size:12px;color:#909399">6666666666</td>
            <td style="border:1px solid #EBEEF5;font-size:12px;color:#909399">6666666666</td>
            <td style="border:1px solid #EBEEF5;font-size:12px;color:#909399">6666666666</td>
            <td style="border:1px solid #EBEEF5;font-size:12px;color:#909399">6666666666</td>
            <td style="border:1px solid #EBEEF5;font-size:12px;color:#909399">6666666666</td>
            <td style="border:1px solid #EBEEF5;font-size:12px;color:#909399">6666666666</td>
            <td style="border:1px solid #EBEEF5;font-size:12px;color:#909399">6666666666</td>
            <td style="border:1px solid #EBEEF5;font-size:12px;color:#909399">6666666666</td>
            <td style="border:1px solid #EBEEF5;font-size:12px;color:#909399">6666666666</td>
          </tr>
        </table>
        <div
          style="font-size: 14px;
      margin-top: 20px;
      width: 100%;
      height: 40px;
      text-align: center;
      line-height: 40px;
      border: 1px solid #ebeef5;"
        >
          <span style="margin: 0 60px;">回货总金额：66666666</span>
          <span style="margin: 0 60px;">回货总数量：99999999999</span>
        </div>
      </div>
      <div style="margin:4mm 0">
        <div style="margin:2mm 0">工序费用</div>
        <table
          style="border:1px solid #EBEEF5;width: 200mm; min-height: 25px; line-height: 25px; text-align: center; border-collapse: collapse; padding:2px;"
        >
          <tr style="border:1px solid #EBEEF5;font-size:12px;color:#909399">
            <th style="border:1px solid #EBEEF5;font-size:12px;color:#909399">工序加工单</th>
            <th style="border:1px solid #EBEEF5;font-size:12px;color:#909399">合同号</th>
            <th style="border:1px solid #EBEEF5;font-size:12px;color:#909399">款号</th>
            <th style="border:1px solid #EBEEF5;font-size:12px;color:#909399">工厂</th>
            <th style="border:1px solid #EBEEF5;font-size:12px;color:#909399">单价</th>
            <th style="border:1px solid #EBEEF5;font-size:12px;color:#909399">数量</th>
            <th style="border:1px solid #EBEEF5;font-size:12px;color:#909399">金额</th>
            <th style="border:1px solid #EBEEF5;font-size:12px;color:#909399">交期</th>
            <th style="border:1px solid #EBEEF5;font-size:12px;color:#909399">创建时间</th>
          </tr>
          <tr>
            <td style="border:1px solid #EBEEF5;font-size:12px;color:#909399">6666666666</td>
            <td style="border:1px solid #EBEEF5;font-size:12px;color:#909399">6666666666</td>
            <td style="border:1px solid #EBEEF5;font-size:12px;color:#909399">6666666666</td>
            <td style="border:1px solid #EBEEF5;font-size:12px;color:#909399">6666666666</td>
            <td style="border:1px solid #EBEEF5;font-size:12px;color:#909399">6666666666</td>
            <td style="border:1px solid #EBEEF5;font-size:12px;color:#909399">6666666666</td>
            <td style="border:1px solid #EBEEF5;font-size:12px;color:#909399">6666666666</td>
            <td style="border:1px solid #EBEEF5;font-size:12px;color:#909399">6666666666</td>
            <td style="border:1px solid #EBEEF5;font-size:12px;color:#909399">6666666666</td>
          </tr>
        </table>
      </div>
      <div style="margin:4mm 0">
        <div style="margin:2mm 0">预付款费用</div>
        <table
          style="border:1px solid #EBEEF5;width: 200mm; min-height: 25px; line-height: 25px; text-align: center; border-collapse: collapse; padding:2px;"
        >
          <tr style="border:1px solid #EBEEF5;font-size:12px;color:#909399">
            <th style="border:1px solid #EBEEF5;font-size:12px;color:#909399">合同号</th>
            <th style="border:1px solid #EBEEF5;font-size:12px;color:#909399">预付款</th>
            <th style="border:1px solid #EBEEF5;font-size:12px;color:#909399">付款时间</th>
          </tr>
          <tr>
            <td style="border:1px solid #EBEEF5;font-size:12px;color:#909399">6666666666</td>
            <td style="border:1px solid #EBEEF5;font-size:12px;color:#909399">6666666666</td>
            <td style="border:1px solid #EBEEF5;font-size:12px;color:#909399">6666666666</td>
          </tr>
        </table>
      </div>
      <div style="margin:4mm 0">
        <div style="margin:2mm 0">额外费用</div>
        <table
          style="border:1px solid #EBEEF5;width: 200mm; min-height: 25px; line-height: 25px; text-align: center; border-collapse: collapse; padding:2px;"
        >
          <tr style="border:1px solid #EBEEF5;font-size:12px;color:#909399">
            <th style="border:1px solid #EBEEF5;font-size:12px;color:#909399">合同号</th>
            <th style="border:1px solid #EBEEF5;font-size:12px;color:#909399">款号</th>
            <th style="border:1px solid #EBEEF5;font-size:12px;color:#909399">款名</th>
            <th style="border:1px solid #EBEEF5;font-size:12px;color:#909399">用途</th>
            <th style="border:1px solid #EBEEF5;font-size:12px;color:#909399">单价</th>
            <th style="border:1px solid #EBEEF5;font-size:12px;color:#909399">数量</th>
            <th style="border:1px solid #EBEEF5;font-size:12px;color:#909399">总价</th>
            <th style="border:1px solid #EBEEF5;font-size:12px;color:#909399">备注</th>
          </tr>
          <tr>
            <td style="border:1px solid #EBEEF5;font-size:12px;color:#909399">6666666666</td>
            <td style="border:1px solid #EBEEF5;font-size:12px;color:#909399">6666666666</td>
            <td style="border:1px solid #EBEEF5;font-size:12px;color:#909399">6666666666</td>
            <td style="border:1px solid #EBEEF5;font-size:12px;color:#909399">6666666666</td>
            <td style="border:1px solid #EBEEF5;font-size:12px;color:#909399">6666666666</td>
            <td style="border:1px solid #EBEEF5;font-size:12px;color:#909399">6666666666</td>
            <td style="border:1px solid #EBEEF5;font-size:12px;color:#909399">6666666666</td>
            <td style="border:1px solid #EBEEF5;font-size:12px;color:#909399">6666666666</td>
          </tr>
        </table>
      </div>
      <div style="margin:4mm 0">
        <div style="margin:2mm 0">违约金/赔偿金金额</div>
        <table
          style="border:1px solid #EBEEF5;width: 200mm; min-height: 25px; line-height: 25px; text-align: center; border-collapse: collapse; padding:2px;"
        >
          <tr style="border:1px solid #EBEEF5;font-size:12px;color:#909399">
            <th style="border:1px solid #EBEEF5;font-size:12px;color:#909399">合同号</th>
            <th style="border:1px solid #EBEEF5;font-size:12px;color:#909399">款号</th>
            <th style="border:1px solid #EBEEF5;font-size:12px;color:#909399">违约金/赔偿金金额</th>
            <th style="border:1px solid #EBEEF5;font-size:12px;color:#909399">违约金/赔偿金原因</th>
            <th style="border:1px solid #EBEEF5;font-size:12px;color:#909399">违约金/赔偿金备注</th>
            <th style="border:1px solid #EBEEF5;font-size:12px;color:#909399">违约金/赔偿金申请日期</th>
          </tr>
          <tr>
            <td style="border:1px solid #EBEEF5;font-size:12px;color:#909399">6666666666</td>
            <td style="border:1px solid #EBEEF5;font-size:12px;color:#909399">6666666666</td>
            <td style="border:1px solid #EBEEF5;font-size:12px;color:#909399">6666666666</td>
            <td style="border:1px solid #EBEEF5;font-size:12px;color:#909399">6666666666</td>
            <td style="border:1px solid #EBEEF5;font-size:12px;color:#909399">6666666666</td>
            <td style="border:1px solid #EBEEF5;font-size:12px;color:#909399">6666666666</td>
          </tr>
        </table>
      </div>
      <div style="margin:4mm 0">
        <div style="margin:2mm 0">对账信息汇总</div>
        <table
          style="border:1px solid #EBEEF5;width: 200mm; min-height: 25px; line-height: 25px; text-align: center; border-collapse: collapse; padding:2px;"
        >
          <tr style="border:1px solid #EBEEF5;font-size:12px;color:#909399">
            <th style="border:1px solid #EBEEF5;font-size:12px;color:#909399">货款金额</th>
            <th style="border:1px solid #EBEEF5;font-size:12px;color:#909399">工序费用</th>
            <th style="border:1px solid #EBEEF5;font-size:12px;color:#909399">预付款</th>
            <th style="border:1px solid #EBEEF5;font-size:12px;color:#909399">额外费用</th>
            <th style="border:1px solid #EBEEF5;font-size:12px;color:#909399">违约金/赔偿金金额</th>
            <th style="border:1px solid #EBEEF5;font-size:12px;color:#909399">总开票金额</th>
            <th style="border:1px solid #EBEEF5;font-size:12px;color:#909399">总应付金额</th>
          </tr>
          <tr>
            <td style="border:1px solid #EBEEF5;font-size:12px;color:#909399">6666666666</td>
            <td style="border:1px solid #EBEEF5;font-size:12px;color:#909399">6666666666</td>
            <td style="border:1px solid #EBEEF5;font-size:12px;color:#909399">6666666666</td>
            <td style="border:1px solid #EBEEF5;font-size:12px;color:#909399">6666666666</td>
            <td style="border:1px solid #EBEEF5;font-size:12px;color:#909399">6666666666</td>
            <td style="border:1px solid #EBEEF5;font-size:12px;color:#909399">6666666666</td>
            <td style="border:1px solid #EBEEF5;font-size:12px;color:#909399">6666666666</td>
          </tr>
        </table>
      </div>
    </div>-->
  </div>
</template>

<script>
const ExcelJS = require("exceljs");
import FileSaver from "file-saver";
import {
  postAdminPricingLookReconciliationOrder,
  postAdminPricingExamineReconciliationOrder,
  postAdminPricingSetPdfExport,
} from "@/api";
import htmlToPdf from "@/utils/htmlToPdf.js";
export default {
  data() {
    return {
      auditdialogVisible: false,
      data: "",
      Priceid: "",
      form: {
        status: 1,
      },
    };
  },
  mounted() {
    let Priceid = this.$route.query.Priceid;
    this.Priceid = Priceid;
    this.postAdminPricingLookReconciliationOrder();
  },
  methods: {
    onExportPDF() {
      // let data = this.data;
      // htmlToPdf.getPdf(
      //   `${data.factory_name} ${data.recon_time} 入库结账对账单`,
      //   "#pdfDom"
      // );

      // let obj = {
      //   id: this.Priceid,
      // };
      //  postAdminPricingSetPdfExport(obj).then((res) => {
      //   console.log("导出PDF----------->", obj);
      // });
      let url = `https://ssy.13yu.com//index.php/Admin/Pricing/setPdfExport?id=${this.Priceid}`;
      window.open(url);
    },
    onExport() {
      let data = this.data;
      // htmlToPdf.getPdf(
      //   `${data.factory_name} ${data.recon_time} 入库结账对账单`,
      //   "#pdfDom"
      // );
      // let obj = {
      //   id: this.Priceid,
      // };
      // postAdminPricingSetPdfExport(obj).then(res=>{
      //   console.log("导出PDF----------->",obj);
      // })
      // let url = `https://ssy.13yu.com//index.php/Admin/Pricing/setPdfExport?id=${this.Priceid}`;
      // window.open(url);
      // 回货单
      let purchaseinlist = data.purchaseinlist;
      let arrpurchasein = [];
      for (let index = 0; index < purchaseinlist.length; index++) {
        let arr = [];
        arr[0] = purchaseinlist[index].so_id;
        arr[1] = purchaseinlist[index].factory_contract_no;
        arr[2] = purchaseinlist[index].po_id;
        arr[3] = purchaseinlist[index].type_no;
        arr[4] = purchaseinlist[index].type_name;
        arr[5] = purchaseinlist[index].contract_machining_price;
        arr[6] = purchaseinlist[index].pay_machining_price;
        arr[7] = purchaseinlist[index].totalnum;
        arr[8] = purchaseinlist[index].total_cost_amount;
        arr[9] = purchaseinlist[index].emb_billing_amount;
        arrpurchasein.push(arr);
      }
      // 工序费用
      let worklist = data.worklist;
      let arrworklist = [];
      if (worklist.length) {
        for (let index = 0; index < worklist.length; index++) {
          let arr = [];
          arr[0] = worklist[index].working_number;
          arr[1] = worklist[index].factory_contract_no;
          arr[2] = worklist[index].type_no;
          arr[3] = worklist[index].factory_name;
          arr[4] = worklist[index].price;
          arr[5] = worklist[index].num;
          arr[6] = worklist[index].amount;
          arr[7] = worklist[index].delivery_date;
          arr[8] = worklist[index].createtime;
          arrworklist.push(arr);
        }
      } else {
        arrworklist = [, , , , , , , ,];
      }

      // 预付款费用
      let advancelist = data.advancelist;
      let arradvancelist = [];
      if (advancelist.length) {
        for (let index = 0; index < advancelist.length; index++) {
          let arr = [];
          arr[0] = advancelist[index].factory_contract_no;
          arr[1] = advancelist[index].amount;
          arr[2] = advancelist[index].pay_time;
          arradvancelist.push(arr);
        }
      } else {
        arradvancelist = [[, ,]];
      }

      // 额外费用
      let additionallist = data.additionallist;
      let arradditionallist = [];
      if (additionallist.length) {
        for (let index = 0; index < additionallist.length; index++) {
          let arr = [];
          arr[0] = additionallist[index].factory_contract_no;
          arr[1] = additionallist[index].processing_code;
          arr[2] = additionallist[index].type_no;
          arr[3] = additionallist[index].type_name;
          arr[4] = additionallist[index].purpose;
          arr[5] = additionallist[index].price;
          arr[6] = additionallist[index].tax_rate_price;
          arr[7] = additionallist[index].num;
          arr[8] = additionallist[index].amount;
          arr[9] = additionallist[index].remarks;
          arradditionallist.push(arr);
        }
      } else {
        arradditionallist = [[, , , , , , , , ,]];
      }

      // 违约金/赔偿金
      let finelist = data.finelist;
      let arrfinelist = [];
      if (finelist.length) {
        for (let index = 0; index < finelist.length; index++) {
          let arr = [];
          arr[0] = finelist[index].factory_contract_no;
          arr[1] = finelist[index].processing_code;
          arr[2] = finelist[index].type_name;
          arr[3] = finelist[index].type_no;
          arr[4] = finelist[index].amount;
          arr[5] = finelist[index].reason;
          arr[6] = finelist[index].remarks;
          arr[7] = finelist[index].createtime;
          arrfinelist.push(arr);
        }
      } else {
        arrfinelist = [[, , , , , , ,]];
      }

      // 返修退款
      let repairlist = data.repairlist;
      let arrrepairlist = [];
      if (repairlist.length) {
        for (let index = 0; index < repairlist.length; index++) {
          let arr = [];
          arr[0] = repairlist[index].processing_code;
          arr[1] = repairlist[index].po_id;
          arr[2] = repairlist[index].type_no;
          arr[3] = repairlist[index].contract_machining_price;
          arr[4] = repairlist[index].pay_machining_price;
          arr[5] = "-" + repairlist[index].num;
          arr[6] = "-" + repairlist[index].amount;
          arrrepairlist.push(arr);
        }
      } else {
        arrrepairlist = [[, , , , , ,]];
      }

      // 对账信息汇总
      let Summary = data.Summary;
      let arrSummary = [];
      for (let index = 0; index < Summary.length; index++) {
        let arr = [];
        arr[0] = Summary[index].purchasein_amount || 0;
        arr[1] = Summary[index].work_amount || 0;
        arr[2] = Summary[index].advance_amount || 0;
        arr[3] = Summary[index].additional_amount || 0;
        arr[4] = Summary[index].fine_amount || 0;
        arr[5] = Summary[index].repair_amount || 0;
        arr[6] = Summary[index].kaip_amount || 0;
        arr[7] = Summary[index].pay_amount || 0;
        arrSummary.push(arr);
      }

      // 工厂银行信息
      let bank = data.bank;
      let arrbank = [];
      for (let index = 0; index < bank.length; index++) {
        let arr = [];
        arr[0] = bank[index].company_head;
        arr[1] = bank[index].bank_of_deposit;
        arr[2] = bank[index].opening_bank_no;
        arr[3] = bank[index].bank_account;
        arrbank.push(arr);
      }
      const tableTitle = data.factory_name + data.recon_time + "入库结账对账单";
      const workbook = new ExcelJS.Workbook();
      workbook.creator = tableTitle;
      workbook.lastModifiedBy = tableTitle;
      workbook.created = new Date();
      workbook.modified = new Date();
      // 将工作簿日期设置为 1904 年日期系统
      // workbook.properties.date1904 = true;
      const worksheet = workbook.addWorksheet(tableTitle);
      worksheet.properties.defaultColWidth = 26; // 默认列宽
      worksheet.properties.defaultRowHeight = 20; // 默认行高
      //定义回货单标题
      const purchaseinrow = worksheet.getRow(1);
      purchaseinrow.height = 50;
      const purchaseincell = worksheet.getCell("A1");
      worksheet.mergeCells("A1:I1");
      purchaseincell.value =
        data.factory_name + data.recon_time + "入库结账对账单";
      purchaseincell.font = { name: "宋体", family: 4, size: 14, bold: true }; // 字体
      purchaseincell.alignment = { vertical: "middle", horizontal: "center" }; //对齐

      worksheet.addTable({
        name: "purchasein",
        ref: "A2",
        displayName: "",
        headerRow: true, // 在表格顶部显示标题
        filterButton: false, // 切换标题中的过滤器控件
        totalsRow: false, // 在表格底部显示总计
        style: {
          theme: "TableStyleLight8",
        },
        columns: [
          { name: "生产加工单" },
          { name: "合同号" },
          { name: "采购单号" },
          { name: "款号" },
          { name: "款名" },
          { name: "大货绣花成本加价总价(含税)" },
          { name: "实付绣花成本加价总价(含税)" },
          { name: "数量" },
          { name: "货款金额(含税)" },
          { name: "开票金额" },
        ],
        rows: arrpurchasein,
      });
      //定义回货单总计标题
      const purchaseintitlerow = worksheet.getRow(arrpurchasein.length + 3);
      purchaseintitlerow.height = 50;
      const purchaseintitlecell = worksheet.getCell(
        `A${arrpurchasein.length + 3}`
      );
      worksheet.mergeCells(
        `A${arrpurchasein.length + 3}:I${arrpurchasein.length + 3}`
      );
      purchaseintitlecell.value = `回货总金额：${data.purchasein_amount}     回货总数量：${data.totalnum}`;
      purchaseintitlecell.font = {
        name: "宋体",
        family: 4,
        size: 14,
        bold: true,
      }; // 字体
      purchaseintitlecell.alignment = {
        vertical: "middle",
        horizontal: "center",
      }; //对齐

      // worksheet.addTable({
      //   name: "purchaseintitle",
      //   ref: `A${arrpurchasein.length + 3}`,
      //   displayName: "",
      //   headerRow: true, // 在表格顶部显示标题
      //   filterButton: false, // 切换标题中的过滤器控件
      //   totalsRow: false, // 在表格底部显示总计
      //   style: {
      //     theme: "TableStyleLight8",
      //   },
      //   columns: [
      //     {name:""}
      //   ],
      //   rows: [],
      // });
      //定义工序费用标题
      const worklistrow = worksheet.getRow(arrpurchasein.length + 5);
      worklistrow.height = 50;
      const worklistcell = worksheet.getCell(`A${arrpurchasein.length + 5}`);
      worksheet.mergeCells(
        `A${arrpurchasein.length + 5}:I${arrpurchasein.length + 5}`
      );
      worklistcell.value = "工序费用";
      worklistcell.font = { name: "宋体", family: 4, size: 14, bold: true }; // 字体
      worklistcell.alignment = { vertical: "middle", horizontal: "center" }; //对齐

      worksheet.addTable({
        name: "worklist",
        ref: `A${arrpurchasein.length + 6}`,
        displayName: "",
        headerRow: true, // 在表格顶部显示标题
        filterButton: false, // 切换标题中的过滤器控件
        totalsRow: false, // 在表格底部显示总计
        style: {
          theme: "TableStyleLight8",
        },
        columns: [
          { name: "工序加工单" },
          { name: "合同号" },
          { name: "款号" },
          { name: "工厂" },
          { name: "单价" },
          { name: "数量" },
          { name: "金额" },
          { name: "交期" },
          { name: "创建时间" },
        ],
        rows: arrworklist,
      });
      //定义预付款费用标题
      const advancelistrow = worksheet.getRow(
        arrpurchasein.length + arrworklist.length + 10
      );
      advancelistrow.height = 50;
      const advancelistcell = worksheet.getCell(
        `A${arrpurchasein.length + arrworklist.length + 10}`
      );
      worksheet.mergeCells(
        `A${arrpurchasein.length + arrworklist.length + 10}:C${arrpurchasein.length + arrworklist.length + 10
        }`
      );
      advancelistcell.value = "预付款费用";
      advancelistcell.font = { name: "宋体", family: 4, size: 14, bold: true }; // 字体
      advancelistcell.alignment = { vertical: "middle", horizontal: "center" }; //对齐

      worksheet.addTable({
        name: "advancelist",
        ref: `A${arrpurchasein.length + arrworklist.length + 11}`,
        displayName: "",
        headerRow: true, // 在表格顶部显示标题
        filterButton: false, // 切换标题中的过滤器控件
        totalsRow: false, // 在表格底部显示总计
        style: {
          theme: "TableStyleLight8",
        },
        columns: [{ name: "合同号" }, { name: "预付款" }, { name: "付款时间" }],
        rows: arradvancelist,
      });
      //定义额外费用标题
      const additionallistrow = worksheet.getRow(
        arrpurchasein.length + arrworklist.length + arradvancelist.length + 15
      );
      additionallistrow.height = 50;
      const additionallistcell = worksheet.getCell(
        `A${arrpurchasein.length + arrworklist.length + arradvancelist.length + 15
        }`
      );
      worksheet.mergeCells(
        `A${arrpurchasein.length + arrworklist.length + arradvancelist.length + 15
        }:J${arrpurchasein.length + arrworklist.length + arradvancelist.length + 15
        }`
      );
      additionallistcell.value = "额外费用";
      additionallistcell.font = {
        name: "宋体",
        family: 4,
        size: 14,
        bold: true,
      }; // 字体
      additionallistcell.alignment = {
        vertical: "middle",
        horizontal: "center",
      }; //对齐

      worksheet.addTable({
        name: "additionallist",
        ref: `A${arrpurchasein.length + arrworklist.length + arradvancelist.length + 16
          }`,
        displayName: "",
        headerRow: true, // 在表格顶部显示标题
        filterButton: false, // 切换标题中的过滤器控件
        totalsRow: false, // 在表格底部显示总计
        style: {
          theme: "TableStyleLight8",
        },
        columns: [
          { name: "合同号" },
          { name: "加工单号" },
          { name: "款号" },
          { name: "款名" },
          { name: "用途" },
          { name: "单价" },
          { name: "税额" },
          { name: "数量" },
          { name: "总价" },
          { name: "备注" },
        ],
        rows: arradditionallist,
      });
      //定义违约金/赔偿金标题
      const finelistrow = worksheet.getRow(
        arrpurchasein.length +
        arrworklist.length +
        arradvancelist.length +
        arradditionallist.length +
        20
      );
      finelistrow.height = 50;
      const finelistcell = worksheet.getCell(
        `A${arrpurchasein.length +
        arrworklist.length +
        arradvancelist.length +
        arradditionallist.length +
        20
        }`
      );
      worksheet.mergeCells(
        `A${arrpurchasein.length +
        arrworklist.length +
        arradvancelist.length +
        arradditionallist.length +
        20
        }:H${arrpurchasein.length +
        arrworklist.length +
        arradvancelist.length +
        arradditionallist.length +
        20
        }`
      );
      finelistcell.value = "违约金/赔偿金";
      finelistcell.font = { name: "宋体", family: 4, size: 14, bold: true }; // 字体
      finelistcell.alignment = { vertical: "middle", horizontal: "center" }; //对齐

      worksheet.addTable({
        name: "finelist",
        ref: `A${arrpurchasein.length +
          arrworklist.length +
          arradvancelist.length +
          arradditionallist.length +
          21
          }`,
        displayName: "",
        headerRow: true, // 在表格顶部显示标题
        filterButton: false, // 切换标题中的过滤器控件
        totalsRow: false, // 在表格底部显示总计
        style: {
          theme: "TableStyleLight8",
        },
        columns: [
          { name: "合同号" },
          { name: "加工单号" },
          { name: "款名" },
          { name: "款号" },
          { name: "违约金/赔偿金" },
          { name: "违约/赔偿事由" },
          { name: "备注" },
          { name: "违约/赔偿申请日期" },
        ],
        rows: arrfinelist,
      });
      //定义返修退款标题
      const repairlistrow = worksheet.getRow(
        arrpurchasein.length +
        arrworklist.length +
        arradvancelist.length +
        arradditionallist.length +
        arrfinelist.length +
        25
      );
      repairlistrow.height = 50;
      const repairlistcell = worksheet.getCell(
        `A${arrpurchasein.length +
        arrworklist.length +
        arradvancelist.length +
        arradditionallist.length +
        arrfinelist.length +
        25
        }`
      );
      worksheet.mergeCells(
        `A${arrpurchasein.length +
        arrworklist.length +
        arradvancelist.length +
        arradditionallist.length +
        arrfinelist.length +
        25
        }:G${arrpurchasein.length +
        arrworklist.length +
        arradvancelist.length +
        arradditionallist.length +
        arrfinelist.length +
        25
        }`
      );
      repairlistcell.value = "返修退款";
      repairlistcell.font = { name: "宋体", family: 4, size: 14, bold: true }; // 字体
      repairlistcell.alignment = { vertical: "middle", horizontal: "center" }; //对齐

      worksheet.addTable({
        name: "repairlist",
        ref: `A${arrpurchasein.length +
          arrworklist.length +
          arradvancelist.length +
          arradditionallist.length +
          arrfinelist.length +
          26
          }`,
        displayName: "",
        headerRow: true, // 在表格顶部显示标题
        filterButton: false, // 切换标题中的过滤器控件
        totalsRow: false, // 在表格底部显示总计
        style: {
          theme: "TableStyleLight8",
        },
        columns: [
          { name: "生产加工单" },
          { name: "采购单" },
          { name: "款号" },
          { name: "大货成衣成本加价总价(含税)" },
          { name: "实付成衣成本加价总价(含税)" },
          { name: "数量" },
          { name: "返修退款金额" },
        ],
        rows: arrrepairlist,
      });
      //定义对账信息汇总标题
      const Summaryrow = worksheet.getRow(
        arrpurchasein.length +
        arrworklist.length +
        arradvancelist.length +
        arradditionallist.length +
        arrfinelist.length +
        arrrepairlist.length +
        30
      );
      Summaryrow.height = 50;
      const Summarycell = worksheet.getCell(
        `A${arrpurchasein.length +
        arrworklist.length +
        arradvancelist.length +
        arradditionallist.length +
        arrfinelist.length +
        arrrepairlist.length +
        30
        }`
      );
      worksheet.mergeCells(
        `A${arrpurchasein.length +
        arrworklist.length +
        arradvancelist.length +
        arradditionallist.length +
        arrfinelist.length +
        arrrepairlist.length +
        30
        }:H${arrpurchasein.length +
        arrworklist.length +
        arradvancelist.length +
        arradditionallist.length +
        arrfinelist.length +
        arrrepairlist.length +
        30
        }`
      );
      Summarycell.value = "对账信息汇总";
      Summarycell.font = { name: "宋体", family: 4, size: 14, bold: true }; // 字体
      Summarycell.alignment = { vertical: "middle", horizontal: "center" }; //对齐

      worksheet.addTable({
        name: "Summary",
        ref: `A${arrpurchasein.length +
          arrworklist.length +
          arradvancelist.length +
          arradditionallist.length +
          arrfinelist.length +
          arrrepairlist.length +
          31
          }`,
        displayName: "",
        headerRow: true, // 在表格顶部显示标题
        filterButton: false, // 切换标题中的过滤器控件
        totalsRow: false, // 在表格底部显示总计
        style: {
          theme: "TableStyleLight8",
        },
        columns: [
          { name: "货款金额" },
          { name: "工序费用" },
          { name: "预付款" },
          { name: "额外费用" },
          { name: "违约金/赔偿金" },
          { name: "返修退款" },
          { name: "总开票金额" },
          { name: "总应付金额" },
        ],
        rows: arrSummary,
      });
      //定义工厂银行信息标题
      const bankrow = worksheet.getRow(
        arrpurchasein.length +
        arrworklist.length +
        arradvancelist.length +
        arradditionallist.length +
        arrfinelist.length +
        arrrepairlist.length +
        arrSummary.length +
        35
      );
      bankrow.height = 50;
      const bankcell = worksheet.getCell(
        `A${arrpurchasein.length +
        arrworklist.length +
        arradvancelist.length +
        arradditionallist.length +
        arrfinelist.length +
        arrrepairlist.length +
        arrSummary.length +
        35
        }`
      );
      worksheet.mergeCells(
        `A${arrpurchasein.length +
        arrworklist.length +
        arradvancelist.length +
        arradditionallist.length +
        arrfinelist.length +
        arrrepairlist.length +
        arrSummary.length +
        35
        }:D${arrpurchasein.length +
        arrworklist.length +
        arradvancelist.length +
        arradditionallist.length +
        arrfinelist.length +
        arrrepairlist.length +
        arrSummary.length +
        35
        }`
      );
      bankcell.value = "工厂银行信息";
      bankcell.font = { name: "宋体", family: 4, size: 14, bold: true }; // 字体
      bankcell.alignment = { vertical: "middle", horizontal: "center" }; //对齐

      worksheet.addTable({
        name: "bank",
        ref: `A${arrpurchasein.length +
          arrworklist.length +
          arradvancelist.length +
          arradditionallist.length +
          arrfinelist.length +
          arrrepairlist.length +
          arrSummary.length +
          36
          }`,
        displayName: "",
        headerRow: true, // 在表格顶部显示标题
        filterButton: false, // 切换标题中的过滤器控件
        totalsRow: false, // 在表格底部显示总计
        style: {
          theme: "TableStyleLight8",
        },
        columns: [
          { name: "公司抬头" },
          { name: "开户行" },
          { name: "开户行号" },
          { name: "银行账户" },
        ],
        rows: arrbank,
      });
      workbook.xlsx.writeBuffer().then((buffer) => {
        // eslint-disable-next-line no-undef
        console.log("buffer", buffer);
        FileSaver.saveAs(
          new Blob([buffer], {
            type: "application/octet-stream",
          }),
          `${tableTitle}.xlsx`
        );
      });
    },
    // 确认审核
    onExamineAuditAffirm() {
      let { form, Priceid } = this;
      form.id = Priceid;
      postAdminPricingExamineReconciliationOrder(form).then((res) => {
        this.auditdialogVisible = false;
        this.postAdminPricingLookReconciliationOrder();
      });
    },
    // 审核
    onExamine() {
      this.auditdialogVisible = true;
    },
    // 回货单详情
    async postAdminPricingLookReconciliationOrder(e) {
      this.loading = true;
      let obj = {
        id: this.Priceid,
      };
      await postAdminPricingLookReconciliationOrder(obj)
        .then((res) => {
          let data = res.data;
          data.Summary = [
            {
              purchasein_amount: data.purchasein_amount,
              advance_amount: data.advance_amount,
              additional_amount: data.additional_amount,
              fine_amount: data.fine_amount,
              kaip_amount: data.kaip_amount,
              work_amount: data.work_amount,
              pay_amount: data.pay_amount,
              repair_amount: data.repair_amount,
            },
          ];
          if (data.bank) {
            data.bank = [
              {
                bank_of_deposit: data.bank.bank_of_deposit,
                company_head: data.bank.company_head,
                bank_account: data.bank.bank_account,
                opening_bank_no: data.bank.opening_bank_no,
              },
            ];
          }

          this.data = data;
        })
        .catch((err) => {
          this.loading = false;
        });
    },
  },
};
</script>

<style lang="scss" scoped>
.ReconciliationDetail {
  background: #ffff;
  padding: 20px;
  border-radius: 2px;
  @include boxShadow;

  &-model {
    padding: 40px;

    /deep/ .el-table .cell {
      line-height: normal !important;
    }

    >div:nth-child(1) {
      text-align: center;
      font-size: 20px;
      font-weight: bold;
      margin-bottom: 20px;
    }

    >div:not(:nth-child(1)) {
      padding-bottom: 40px;
      border-bottom: 1px dashed #999999;

      >div:nth-child(1) {
        font-size: 16px;
        margin: 40px 0 10px;
      }
    }

    &-only {

      font-size: 14px;
      margin-top: 20px;
      width: 100%;
      height: 30px;
      text-align: center;
      line-height: 30px;
      border: 1px solid #ebeef5;

      >span {
        margin: 0 60px;
      }
    }
  }
}
</style>